<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小说提现页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 80%;
            margin: 50px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #333;
        }
        form {
            display: flex;
            flex-direction: column;
        }
        label {
            margin-bottom: 5px;
            color: #555;
        }
        input[type="text"],
        input[type="number"],
        select {
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        input[type="submit"] {
            padding: 10px 20px;
            background-color: #28a745;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #218838;
        }
        .error {
            color: red;
            font-size: 0.9em;
        }
        .user-info {
            margin-bottom: 20px;
            text-align: center;
        }
        .user-info p {
            margin: 5px 0;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>小说提现申请</h1>
    <div class="user-info">
        <p>用户名：<span id="usernameDisplay"></span></p>
        <p>账户余额：<span id="accountBalanceDisplay"></span> 元</p>
    </div>
    <form id="withdrawalForm">
        <label for="amount">提现金额：</label>
        <input type="number" id="amount" name="amount"  placeholder="请输入提现金额" step="0.01" min="0.01" max="1000000" required>

        <label for="paymentMethod">支付方式：</label>
        <select id="paymentMethod" name="paymentMethod">
            <option value="">请选择支付方式</option>
            <option value="wechat">微信支付</option>
            <option value="alipay">支付宝</option>
        </select>

        <p>用户名：<span id="Display"></span></p>

        <input type="submit" value="提交提现申请">
    </form>
    <div id="errorMessage" class="error"></div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>


    $(document).ready(function() {
        // 查询用户信息
        $.ajax({
            type: "get",
            url: "/author/queryAuthor01",
            data: {},
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {

                    // 填充用户信息
                    if (data.data.penName) {
                        $("#usernameDisplay").text(data.data.penName); // 假设penName是用户名
                        $("#Display").text(data.data.penName);
                    } else {
                        $("#usernameDisplay").text(data.data.telPhone); // 假设telPhone是用户名
                        $("#Display").text(data.data.telPhone);

                    }

                    $("#accountBalanceDisplay").text(data.data.totalAmount); // 假设totalAmount是账户余额
                }
            },
            error: function () {
                alert('网络异常');
            }
        });
        // 提交表单时的验证逻辑
        $("#withdrawalForm").submit(function(event) {
            event.preventDefault(); // 阻止表单默认提交行为

            var amount = $("#amount").val();
            var paymentMethod = $("#paymentMethod").val();
            var accountBalance = parseFloat($("#accountBalanceDisplay").text()); // 获取账户余额
            if (!amount || !paymentMethod) {
                $("#errorMessage").text("请填写所有必填项！");
                return;
            }
            amount = parseFloat(amount); // 转换提现金额为数字类型
            if (amount > accountBalance) {
                $("#errorMessage").text("提现金额不能大于账户余额！");
                return;
            }
            // 如果验证通过，可以发送数据到服务器
            $.ajax({
                type: "post",
                url: "/author/withdrawDeposit", // 假设这是提交提现申请的接口
                data: {
                    amount: amount,
                },
                dataType: "json",
                success: function(response) {
                    if (response.code == 200) {
                        alert("恭喜您提现成功！")
                        // 可以在这里进行页面跳转或其他操作
                        window.location.href = "/author/author_income_detail.html"
                    } else {
                        alert(response.msg);
                    }
                },
                error: function() {
                    alert("提交失败，请稍后再试！");
                }
            });
        });
    });
</script>
</body>
</html>